package com.leyou.test1.demo;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

public class DataDemo {
    public static void main(String[] args) {
        //日期的操作
        /*
        * LocalDate ： 只含年月日的日期对象
LocalTime ：只含时分秒的时间对象
LocalDateTime ： 同时含有年月日时分秒的日期对象*/
        /*LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDate);
        System.out.println(localTime);
        System.out.println(localDateTime);*/
      /*  Date date = new Date();
        System.out.println(date);*/
       // LocalDateTime now = LocalDateTime.now();
       /* SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(now);
        System.out.println(format);*/
      /*  System.out.println(now);
        LocalDateTime date2 = LocalDateTime.of(2019, 11, 28, 14, 30, 10);
        System.out.println(date2);
        Duration duration = Duration.between(now, date2);
        System.out.println(duration.getSeconds());*/

      /*  HashMap<String, String> map = new HashMap<>();
        map.put("a","aa");
        map.put("c","cc");
        map.put("b","bb");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry);
        }*/
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        int year = now.getYear();
        int mon = now.getMonthValue();
        LocalDateTime ld = LocalDateTime.of(year, mon, 01, 00, 00, 01);
        System.out.println(ld);
        String format = DateTimeFormatter.ofPattern("yyyy-MM").format(ld);
        System.out.println(format);

        LocalDate today = LocalDate.now();
        //本月的第一天
        LocalDate firstday = LocalDate.of(today.getYear(),today.getMonth(),1);
        //本月的最后一天
        LocalDate lastDay =today.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("本月的第一天"+firstday);
        System.out.println("本月的最后一天"+lastDay);

                 //格式化
        DateTimeFormatter newFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
         LocalDate date2 = LocalDate.now();
         System.out.println(date2.format(newFormatter));

    }
}
